package network.editor;

import java.awt.GridLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;

import com.mxgraph.model.mxCell;
import com.mxgraph.model.mxGeometry;

/**
 * 矢量图例的编辑面板
 * 
 * @author zhangzuoqiang <br/>
 *         Date: Aug 25, 2011
 */
public class EditorGeoVertexPanel extends AbstarctEditorPanel {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public EditorGeoVertexPanel() {
		init();
	}

	private void init() {
		GeoResource geoResource = EditorResource.getGeoResource();
		int edgeNodeCount = geoResource.getNames().size();// 获得图片的数量
		if (edgeNodeCount > 0) {
			setLayout(new GridLayout(0, 3));// 3列，任意行
			for (int i = 0; i < edgeNodeCount; i++) {
				ImageIcon sourceIcon = (ImageIcon) geoResource.getIcons()
						.get(i);// 边的图标
				// 边的尺寸默认是100*100,边不显示文字，所以带一个“”的对象
				addGeo(geoResource.getNames().get(i), sourceIcon, geoResource
						.getStyles().get(i), 80, 60, "");
			}
		}
	}

	public void addGeo(final String name, ImageIcon icon, String style,
			int width, int height, Object value) {
		mxCell cell = new mxCell(value, new mxGeometry(0, 0, width, height),
				style);
		cell.setVertex(true);
		addImageLabel(name, icon, cell);
	}

	public static void main(String[] args) {
		JFrame frame = new JFrame();
		frame.setDefaultCloseOperation(3);
		frame.getContentPane().add(new EditorGeoVertexPanel());
		frame.setVisible(true);

		frame.pack();
	}
}